import { getOrgListApi } from '@/api/system/org'

// 获取机构列表hooks
export default function useGetOrgList() {
  const orgOptions = ref([])
  const orgFilterOptions = ref([])
  const orgLoading = ref(false)
  const { userInfo } = getUserInfo()

  const fetchGetOrgList = async () => {
    orgLoading.value = true
    const res = await getOrgListApi()
    if (res.code === '0000') {
      orgOptions.value = res.data
      orgFilterOptions.value = res.data
        .filter((item) => item.value !== userInfo.value.orgId.toString())
        .map((item) => {
          return {
            label: item.label,
            value: item.value
          }
        })
    }
    orgLoading.value = false
  }

  fetchGetOrgList()

  return {
    fetchGetOrgList,
    orgOptions,
    orgFilterOptions,
    orgLoading
  }
}
